home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Event Handling / ToolboxEvent.h < prev   
Encoding:
C/C++ Source or Header  |  1998-06-02  |  2.5 KB  |  126 lines  |  [TEXT/CWIE]

  1. #ifndef __TOOLBOXEVENT__
  2. #define __TOOLBOXEVENT__
  3. #pragma once
  4.  
  5. #include <Events.h>
  6.  
  7.     enum EventClass
  8.     {
  9.         kEvtUnknown,
  10.         kEvtIdle,        // null
  11.         kEvtMouse,        // mouseDown/mouseUp/mouseMoved
  12.         kEvtKeyboard,    // keyDown/keyUp/autoKey
  13.         kEvtDisk,        // diskEvt
  14.         kEvtUpdate,        // updateEvt
  15.         kEvtActivate,    // activate/resume
  16.         kEvtDectivate,    // deactivate/suspend
  17.         kEvtHighLevel
  18.     };
  19.  
  20. #if PRAGMA_STRUCT_ALIGN
  21.     #pragma options align=mac68k
  22. #elif PRAGMA_STRUCT_PACKPUSH
  23.     #pragma pack(push, 2)
  24. #elif PRAGMA_STRUCT_PACK
  25.     #pragma pack(2)
  26. #endif
  27.  
  28.     struct KeyEvtMessage
  29.     {
  30.         Byte    filler;
  31.         Byte    adbAddr;
  32.         Byte    keyCode;
  33.         Byte    chrCode;
  34.     };
  35.  
  36.     struct OSEvtMessage
  37.     {
  38.         Byte    message;
  39.         Byte    filler1;
  40.         Byte    filler2;
  41.         bool    filler3            : 6;
  42.         bool    convertClip        : 1;
  43.         bool    resumeFlag        : 1;
  44.     };
  45.  
  46.     struct EvtModifierBits
  47.     {
  48.         bool    rightControlKey    : 1;
  49.         bool    rightOptionKey    : 1;
  50.         bool    rightShiftKey    : 1;
  51.         bool    controlKey        : 1;
  52.  
  53.         bool    optionKey        : 1;
  54.         bool    alphaLock        : 1;
  55.         bool    shiftKey        : 1;
  56.         bool    cmdKey            : 1;
  57.  
  58.         bool    btnState        : 1;
  59.         bool    filler            : 6;
  60.         bool    activeFlag        : 1;
  61.     };
  62.     
  63.     union EvtMessage
  64.     {
  65.         KeyEvtMessage    key;
  66.         OSEvtMessage    os;
  67.         WindowPtr        win;
  68.         long            data;
  69.     };
  70.  
  71.     union EvtModifiers
  72.     {
  73.         EvtModifierBits    bits;
  74.         short            data;
  75.     };
  76.  
  77.     class ToolboxEvent 
  78.     {
  79.     protected:
  80.         short            type;
  81.         short            what;
  82.         EvtMessage        message;
  83.         UInt32            when;
  84.         Point            where;
  85.         EvtModifiers    modifiers;
  86.         short            part;
  87.         WindowPtr        window;
  88.     
  89.     public:
  90.         ToolboxEvent();
  91.         ToolboxEvent(const EventRecord& event);
  92.     
  93.         void                ParseEvent();
  94.     
  95.         inline long         GetEventTime()        { return when; }
  96.         inline EventKind    GetEventKind()        { return what; }
  97.         inline WindowPtr    GetWindow()            { return window; }
  98.         inline short        GetPartCode()        { return part;    }
  99.  
  100.         inline const Point&                GetMousePosition() const    { return where;             }
  101.         inline const EvtModifierBits&    GetModifierBits() const        { return modifiers.bits;    }
  102.  
  103.         inline bool            CmdKeyDown()        { return modifiers.bits.cmdKey; }
  104.  
  105.         inline Byte            GetCharCode()        { return message.key.chrCode; }
  106.         inline Byte            GetKeyCode()        { return message.key.keyCode; }
  107.         inline Byte            GetADBAddr()        { return message.key.adbAddr; }
  108.         
  109.         inline bool            IsNullEvent()        { return what == nullEvent; }
  110.         inline bool            IsHighLevelEvent()    { return what == kHighLevelEvent; }
  111.         
  112.         inline void            SetToNullEvent()    { type = kEvtIdle; what = nullEvent; }
  113.         
  114.         inline operator EventRecord*()            { return (EventRecord*) &what; }
  115.     };
  116.     
  117.  
  118. #if PRAGMA_STRUCT_ALIGN
  119.     #pragma options align=reset
  120. #elif PRAGMA_STRUCT_PACKPUSH
  121.     #pragma pack(pop)
  122. #elif PRAGMA_STRUCT_PACK
  123.     #pragma pack()
  124. #endif
  125.  
  126. #endif __TOOLBOXEVENT__